home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / portmap.shar / pmap_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  1.5 KB  |  71 lines

  1.  /*
  2.   * pmap_set - set portmapper table from data produced by pmap_dump
  3.   * 
  4.   * Author: Wietse Venema (wietse@wzv.win.tue.nl), dept. of Mathematics and
  5.   * Computing Science, Eindhoven University of Technology, The Netherlands.
  6.   */
  7.  
  8. #ifndef lint
  9. static char sccsid[] = "@(#) pmap_set.c 1.1 92/06/11 22:53:16";
  10. #endif
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #ifdef SYSV40
  15. #include <netinet/in.h>
  16. #endif
  17. #include <rpc/rpc.h>
  18. #include <rpc/pmap_clnt.h>
  19.  
  20. main(argc, argv)
  21. int     argc;
  22. char  **argv;
  23. {
  24.     struct sockaddr_in addr;
  25.     char    buf[BUFSIZ];
  26.     u_long  prog;
  27.     u_long  vers;
  28.     int     prot;
  29.     unsigned port;
  30.  
  31.     get_myaddress(&addr);
  32.  
  33.     while (fgets(buf, sizeof(buf), stdin)) {
  34.     if (parse_line(buf, &prog, &vers, &prot, &port) == 0) {
  35.         fprintf(stderr, "%s: malformed line: %s", argv[0], buf);
  36.         return (1);
  37.     }
  38.     if (pmap_set(prog, vers, prot, (unsigned short) port) == 0)
  39.         fprintf(stderr, "not registered: %s", buf);
  40.     }
  41.     return (0);
  42. }
  43.  
  44. /* parse_line - convert line to numbers */
  45.  
  46. parse_line(buf, prog, vers, prot, port)
  47. char   *buf;
  48. u_long *prog;
  49. u_long *vers;
  50. int    *prot;
  51. unsigned *port;
  52. {
  53.     char    proto_name[BUFSIZ];
  54.  
  55.     if (sscanf(buf, "%lu %lu %s %u", prog, vers, proto_name, port) != 4) {
  56.     return (0);
  57.     }
  58.     if (strcmp(proto_name, "tcp") == 0) {
  59.     *prot = IPPROTO_TCP;
  60.     return (1);
  61.     }
  62.     if (strcmp(proto_name, "udp") == 0) {
  63.     *prot = IPPROTO_UDP;
  64.     return (1);
  65.     }
  66.     if (sscanf(proto_name, "%d", prot) == 1) {
  67.     return (1);
  68.     }
  69.     return (0);
  70. }
  71.